package acn.spring.core.interceptor;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

import acn.spring.domain.Item;

@Aspect
public class MyAspects {

	@Before("execution(* acn.spring.service.ItemService.addItem(..))")
	public void addItemValidation(JoinPoint joinPoint) {
		System.out.println("called Method:" + joinPoint.getSignature().getName());
		Item item = (Item) joinPoint.getArgs()[0];
		System.out.println("added Item Name:" + item.getName());
		System.out.println("added Item Id:" + item.getId());
	}
	
	@AfterReturning(pointcut = "execution(* acn.spring.service.ItemService.addItem(..))", returning = "item")
	public void addItemPostExecution(JoinPoint joinPoint, Object item) {
		System.out.println("persisted Object Name:" + ((Item)item).getName());
		System.out.println("persisted Object Id:" + ((Item)item).getId());
	}
	
//	@Around("execution(* acn.spring.service.ItemService.addItem(..))")
//	public void around(ProceedingJoinPoint joinPoint) throws Throwable {
//		System.out.println("AROUND before Method:" + joinPoint.getSignature().getName());
//		joinPoint.proceed();
//		System.out.println("AROUND after Method:" + joinPoint.getSignature().getName());
//	}
}
